﻿Imports System.Data
Imports System.Data.OleDb


Public Class frmNhanVien
   
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
       
        Dim sql As String = "select * from NhanVien"
        Dim DATA As New ketnoidulieu()
        dgvnhanvien.DataSource = DATA.ExcuteDataTable(sql)
    End Sub
    Dim DT As DataGridViewRow = Nothing
    Dim LISTDT As DataGridViewSelectedRowCollection = Nothing
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim sql As String = String.Format("Insert into NhanVien(MaNhanVien,HoTen, DiaChi, Ngaysinh, DienThoai,MaTruong) values ('{0}',N'{1}', N'{2}',{3},'{4}','{5}')", txtmanhanvien.Text, txthoten.Text, txtdiachi.Text, CDate(txtngaysinh.Text), txtmatruong.Text)
        Dim INS As New ketnoidulieu()
        INS.SQL_ExecuteNonQuery(sql)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Dim sql As String = String.Format("select * from NhanVien where MaNhanVien='{0}' or HoTen=N'{1}' or MaTruong='{2}'", txtmanv.Text, txtht.Text, txtmt.Text)
        Dim DATA As New ketnoidulieu()
        dgvnhanvien.DataSource = DATA.ExcuteDataTable(sql)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each ROWS As DataGridViewRow In LISTDT
            Dim sql As String = String.Format("delete * from NhanVien where MaNhanVien = '{0}'", ROWS.Cells(0).ToString())
            Dim KN As New ketnoidulieu()
            KN.SQL_ExecuteNonQuery(sql)
            dgvnhanvien.Rows.Remove(ROWS)
        Next
    End Sub


    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

        Dim sql As String = String.Format("Update NhanVien Set HoTen=N'{0}', DiaChi = N'{1}', Ngaysinh ='{2}',DienThoai='{3}',MaTruong='{4}' where MaNhanVien = {5}", txthoten.Text, txtdiachi.Text, CDate(Format(txtngaysinh, "mm/dd/yyyy")), txtdienthoai.Text, txtmatruong.Text, DT.Cells(0))
        Dim INS As New ketnoidulieu()
        INS.SQL_ExecuteNonQuery(sql)
        MessageBox.Show("Kiem tra du lieu !!! ")

    End Sub


End Class